<template>
  <div class="row" :style="rowStyle" :class="rowClass">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: "tRow",
  props: {
    gutter: {
      type: [Number, String]
    },
    align: {
      type: String,
      validator(value) {
        return ["left", "center", "right"].includes(value);
      }
    }
  },
  computed: {
    rowClass() {
      let { align } = this;
      return [align && `align-${align}`];
    },
    rowStyle() {
      let { gutter } = this;
      return {
        marginLeft: -gutter / 2 + "px",
        marginRigth: -gutter / 2 + "px"
      };
    }
  },
  mounted() {
    let gutter = this.gutter;
    this.$children.forEach(vm => {
      vm.gutter = gutter;
    });
  }
};
</script>
<style lang="scss" scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  &.align-left {
    justify-content: flex-start;
  }
  &.align-center {
    justify-content: center;
  }
  &.align-right {
    justify-content: flex-end;
  }
}
</style>
